package com.rst.service;


import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler;


public class CustomAuthenticationFailureHandler extends SimpleUrlAuthenticationFailureHandler{
	
	
	
	private AuthenticationService userManagementService;
	
	
	public CustomAuthenticationFailureHandler(){
		super();
	}
	
	
	public AuthenticationService getUserManagementService() {
		return userManagementService;
	}

	public void setUserManagementService(AuthenticationService userManagementService) {
		this.userManagementService = userManagementService;
	}
	
	
	
	@Override
	public void onAuthenticationFailure(HttpServletRequest httpServletRequest,
			HttpServletResponse httpServletResponse, AuthenticationException authException)
			throws IOException, ServletException {

		//User detailsDTO = (User)authException.getExtraInformation();
		
/*		if(null != detailsDTO) {
			if(null == detailsDTO.getCount()) {
				String userId = detailsDTO.getUsername();
				detailsDTO.setCount(0);
				userManagementService.updateUserDetails(detailsDTO);
				detailsDTO = (UserDetailsDTO)userManagementService.loadUserByUsername(userId);
			}
			
				
			Properties propertyFile = new Properties();
			propertyFile.load(CustomAuthenticationFailureHandler.class.getResourceAsStream("/propertyFiles/switches.properties"));
			String enableAcccountLocking = propertyFile.getProperty("enableAcccountLocking");
			if(enableAcccountLocking.equalsIgnoreCase("1")) {
				logger.debug("Account locking feature enabled");
				userManagementService.accountLocked(detailsDTO);	
			}
		}*/
		
		super.onAuthenticationFailure(httpServletRequest, httpServletResponse, authException);
	}

}
